<template>
	<view class="orderList">
		<view class="orderList-header">
			<view :class="index==indexId?'header-box-active':'header-box'" v-for="(item,index) in headerList"
				:key="index" @click="handleClick(index)">
				{{item}}
			</view>
		</view>
		<view class="orderList-main">
			<view class="main" v-if="records==''" style="text-align: center;margin-top: 20px;color: #999;">
				还没有任何相关订单
			</view>
			<view class="main-box" v-for="(item,index) in records" :key="index">
				<view class="box-header">
					<text>订单编号：{{item.orderNumber}}</text>
					<text v-if="item.status==1">待支付</text>
					<text v-else-if="item.status==2">待发货</text>
					<text v-else-if="item.status==3">待收货</text>
					<text v-else-if="item.status==5">
						<text style="margin-right: 10px;border-right: 1px solid #ddd;padding-right: 10px;">已完成</text>
						<image src="../../static/images/icon/clear-his.png" style="width: 16px; height: 16px;" @click="handleDel"></image>
					</text>
				</view>
				<view class="box-con" @click="handleSpxq(item.orderNumber)">
					<image :src="item.orderItemDtos[0].pic" style="width: 80px;
					height: 80px;"></image>
					<view class="bxo-con-right">
						<view class="right-h">
							{{item.orderItemDtos[0].prodName}}
						</view>
						<view class="right-p">
							{{item.orderItemDtos[0].skuName}}
						</view>
						<view class="right-foot">
							<text>￥{{item.orderItemDtos[0].price}}<text>.00</text> </text>
							<text>x{{item.orderItemDtos[0].prodCount}}</text>
						</view>
					</view>
				</view>
				<view class="box-foot">
					共1件商品 合计：￥{{item.actualTotal }}<text>.00</text>
				</view>
				<view class="dzf" v-if="item.status==1">
					<text>取消订单</text>
					<text>付款</text>
				</view>
				<view class="dzf" v-if="item.status==5">
					<text style="margin-right: unset;" @click="handleCkwl(item.orderNumber)">查看物流</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var http = require("../../utils/http");
	export default {
		data() {
			return {
				headerList: ["全部", "待支付", "待发货", "待收货", "已完成"],
				indexId: "",
				records: "",
			}
		},
		onLoad(option) {
			http.request({
				url: "/p/myOrder/myOrder",
				method: "get",
				data: {
					current: 1,
					size: 10,
					status: option.sts
				},
				callBack: res => {
					this.records = res.records
					// console.log(this.swiperList, "232431");
				}
			})
			if (option.sts == 5) {
				this.handleClick(4)
			} else {
				this.handleClick(option.sts)
			}
		},
		methods: {
			// 跳转订单详情
			handleSpxq(orderNum) {
				uni.navigateTo({
					url: `/pages/order-detail/order-detail?orderNum=${orderNum}`
				})
			},
			handleClick(index) {
				this.indexId = index
				this.sts = index
				if (index == 4) {
					http.request({
						url: "/p/myOrder/myOrder",
						method: "get",
						data: {
							current: 1,
							size: 10,
							status: 5
						},
						callBack: res => {
							this.records = res.records
							// console.log(this.swiperList, "232431");
						}
					})
				} else {
					http.request({
						url: "/p/myOrder/myOrder",
						method: "get",
						data: {
							current: 1,
							size: 10,
							status: index
						},
						callBack: res => {
							this.records = res.records
							// console.log(this.swiperList, "232431");
						}
					})
				}

			},
			// 查看物流
			handleCkwl(orderNumber){
				uni.navigateTo({
					url:`/pages/express-delivery/express-delivery?orderNumber=${orderNumber}`
				})
			},
			// 删除已完成
			handleDel(){
				uni.showModal({
					content: '确认删除？',
					success: (res) => {
						if (res.confirm) {
							// console.log('户点击确定 ');
							http.request({
								// url: `/p/address/deleteAddr/${this.editAddressList.addrId}`,
								method: "DELETE",
								data: {},
								callBack: res => {
									setTimeout(() => {
										this.onLoad()
									}, 100)
								}
							})
						} else if (res.cancel) {
							// console.log('用户点击取消 ');
						}
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.orderList {
		.orderList-header {
			background-color: #fff;
			padding: 10px 10px 0;
			display: flex;
			justify-content: space-between;
			border-bottom: 1upx solid #ececec;

			.header-box {
				width: 15%;
				text-align: center;
			}

			.header-box-active {
				width: 15%;
				text-align: center;
				color: #f00;
				border-bottom: 2px solid #f00;
				padding-bottom: 10px;
			}
		}

		.orderList-main {
			.main-box {
				background-color: #fff;
				margin-bottom: 10px;

				.box-header {
					display: flex;
					justify-content: space-between;
					padding: 10px;

					text {
						&:last-child {
							font-size: 12px;
						}
					}
				}

				.box-con {
					display: flex;
					justify-content: space-between;
					
					padding: 20px 0;
padding: 10px;
					.bxo-con-right {
						width: 72%;
					}

					.right-h {
						height: 36px;
					}

					.right-p {
						height: 20px;
						margin-top: 10upx;
						color: #999;
					}

					.right-foot {
						display: flex;
						justify-content: space-between;
						align-items: center;

						text {
							&:nth-child(1) {
								font-size: 16px;

								text {
									font-size: 12px;
								}
							}

							&:nth-child(2) {
								color: #999;
							}
						}
					}
				}

				.box-foot {
					padding: 10px;
					text-align: right;
					font-size: 14px;
					border-bottom: 1px solid #eee;
					padding-bottom: 10px;

					text {
						font-size: 12px;
					}
				}

				.dzf {
					text-align: right;
					padding: 10px;

					text {
						display: inline-block;

						&:nth-child(1) {
							padding: 4px 10px;
							border: 1px solid #ddd;
							border-radius: 20px;
							margin-right: 10px;
						}

						&:nth-child(2) {
							color: #f00;
							padding: 4px 14px;
							border: 1px solid #f00;
							border-radius: 30px;
						}

					}
				}
			}
		}
	}
</style>